1
2
3
4
5
6
7
8 package gov.noaa.eds.xapi.generic;
9
10 import junit.framework.*;
11 import org.xmldb.api.base.ErrorCodes;
12 import org.xmldb.api.base.Resource;
13 import org.xmldb.api.base.Service;
14 import org.xmldb.api.base.XMLDBException;
15
16 /***
17 *
18 * @author tns
19 */
20 public class GenericCollectionTest extends TestCase {
21
22 GenericCollection collection = null;
23 String resourceId = "1";
24
25 public GenericCollectionTest(String testName) {
26 super(testName);
27 }
28
29 protected void setUp() throws java.lang.Exception {
30 collection = new GenericCollection();
31 GenericDomHandlerResource resource = new GenericDomHandlerResource();
32 resource.setId(resourceId);
33 collection.storeResource(resource);
34 }
35
36 protected void tearDown() throws java.lang.Exception {
37 }
38
39 public static junit.framework.Test suite() {
40 junit.framework.TestSuite suite = new junit.framework.TestSuite(GenericCollectionTest.class);
41
42 return suite;
43 }
44
45
46 /***
47 * Test of getChildCollection method, of class gov.noaa.eds.xapi.generic.GenericCollection.
48 */
49 public void testGetChildCollection() {
50
51 try {
52 collection.getChildCollection("");
53 fail("Exception should have been thrown");
54 } catch (XMLDBException expected){
55 assertEquals("Error should be a NOT_IMPLEMENTED error",expected.errorCode,ErrorCodes.NOT_IMPLEMENTED);
56 }
57 }
58
59 /***
60 * Test of getResource method, of class gov.noaa.eds.xapi.generic.GenericCollection.
61 */
62 public void testGetValidResource() throws Exception {
63 System.out.println("testGetResource");
64
65 Resource res = collection.getResource(resourceId);
66 assertNotNull("Resource should have been found",res);
67 }
68
69 public void testGetInvalidResource() throws Exception {
70 Resource rs = collection.getResource("an invalid id");
71 assertNull("Resource should not have been found",rs);
72 }
73
74 /***
75 * Test of storeResource method, of class gov.noaa.eds.xapi.generic.GenericCollection.
76 */
77 public void testStoreResource() throws Exception {
78 System.out.println("testStoreResource");
79 GenericDomHandlerResource rs = new GenericDomHandlerResource();
80 rs.setId("ID");
81 collection.storeResource(rs);
82
83 Resource r = collection.getResource("ID");
84 assertNotNull("Resource should have been found",r);
85
86 }
87
88 /***
89 * Test of removeResource method, of class gov.noaa.eds.xapi.generic.GenericCollection.
90 */
91 public void testRemoveResource() throws Exception {
92 System.out.println("testRemoveResource");
93 Resource r1 = collection.getResource(resourceId);
94 assertNotNull("resource shold be present",r1);
95
96 collection.removeResource(r1);
97
98 Resource res = collection.getResource(resourceId);
99 assertNull("Resource should not have been found",res);
100
101 }
102
103 /***
104 * Test of listResources method, of class gov.noaa.eds.xapi.generic.GenericCollection.
105 */
106 public void testListResources() {
107 System.out.println("testListResources");
108
109 String[] rs = collection.listResources();
110 assertNotNull("resource list should not be null",rs);
111 assertEquals("resource list should have one item",rs.length,1);
112 assertEquals("unexpected resource id",resourceId,rs[0]);
113 }
114
115 /***
116 * Test of close method, of class gov.noaa.eds.xapi.generic.GenericCollection.
117 */
118 public void testClose() {
119 System.out.println("testClose");
120
121 collection.close();
122 }
123
124 /***
125 * Test of createId method, of class gov.noaa.eds.xapi.generic.GenericCollection.
126 */
127 public void testCreateId() {
128 System.out.println("testCreateId");
129
130 String id = collection.createId();
131 assertNotNull("created id should not be null",id);
132 String id2 = collection.createId();
133 assertNotNull("Created id should not be null",id2);
134 assertTrue("Ids should not be equal",! id.equals(id2));
135 }
136
137 /***
138 * Test of createResource method, of class gov.noaa.eds.xapi.generic.GenericCollection.
139 */
140 public void testCreateResource() {
141 System.out.println("testCreateResource");
142
143 try {
144 collection.createResource("","");
145 fail("expected not implemented");
146 } catch (XMLDBException e){
147 assertEquals("Expected not implemented error",e.errorCode,ErrorCodes.NOT_IMPLEMENTED);
148 }
149 }
150
151 /***
152 * Test of getChildCollectionCount method, of class gov.noaa.eds.xapi.generic.GenericCollection.
153 */
154 public void testGetChildCollectionCount() {
155 System.out.println("testGetChildCollectionCount");
156
157 try {
158 collection.getChildCollectionCount();
159 fail("Exception expected");
160 } catch (XMLDBException expected){
161 assertEquals("Expected not implemented exception",expected.errorCode,ErrorCodes.NOT_IMPLEMENTED);
162 }
163 }
164
165 /***
166 * Test of getName method, of class gov.noaa.eds.xapi.generic.GenericCollection.
167 */
168 public void testGetName() {
169 System.out.println("testGetName");
170
171 collection.setName("xmldb:generic://balh.com/blah");
172 String name = collection.getName();
173 assertEquals("unexpected name",name,"xmldb:generic://balh.com/blah");
174 }
175
176 /***
177 * Test of setName method, of class gov.noaa.eds.xapi.generic.GenericCollection.
178 */
179 public void testSetName() {
180 System.out.println("testSetName");
181
182 collection.setName("Blah");
183 }
184
185 /***
186 * Test of getParentCollection method, of class gov.noaa.eds.xapi.generic.GenericCollection.
187 */
188 public void testGetParentCollection() {
189 System.out.println("testGetParentCollection");
190
191 try {
192 collection.getParentCollection();
193 fail("Exception expected");
194 } catch (XMLDBException e){
195 assertEquals("not implemented exception expected",e.errorCode,ErrorCodes.NOT_IMPLEMENTED);
196 }
197 }
198
199 /***
200 * Test of getResourceCount method, of class gov.noaa.eds.xapi.generic.GenericCollection.
201 */
202 public void testGetResourceCount() {
203 System.out.println("testGetResourceCount");
204
205 int count = collection.getResourceCount();
206 assertEquals("Unexpected count result",1,count);
207 }
208
209 /***
210 * Test of getService method, of class gov.noaa.eds.xapi.generic.GenericCollection.
211 */
212 public void testGetValidService() throws Exception {
213 System.out.println("testGetService");
214
215 Service ser = collection.getService("XPathQueryService","1.0");
216 assertNotNull("service should have been returned",ser);
217 assertEquals("name unexpected","XPathQueryService",ser.getName());
218 assertEquals("version unexpected","1.0",ser.getVersion());
219 }
220
221 /***
222 * Test of getServices method, of class gov.noaa.eds.xapi.generic.GenericCollection.
223 */
224 public void testGetServices() throws Exception {
225 System.out.println("testGetServices");
226
227 Service[] sers = collection.getServices();
228 assertNotNull("should be a service",sers);
229 assertEquals("should be one service",1,sers.length);
230 assertEquals("type should be XPathQueryService","XPathQueryService",sers[0].getName());
231 }
232
233 /***
234 * Test of isOpen method, of class gov.noaa.eds.xapi.generic.GenericCollection.
235 */
236 public void testIsOpen() {
237 System.out.println("testIsOpen");
238
239 boolean open = collection.isOpen();
240 assertTrue("should be open",open);
241
242
243 }
244
245 /***
246 * Test of listChildCollections method, of class gov.noaa.eds.xapi.generic.GenericCollection.
247 */
248 public void testListChildCollections() {
249 System.out.println("testListChildCollections");
250
251 try {
252 collection.listChildCollections();
253 fail("Exception expected");
254 } catch (XMLDBException expected){
255 assertEquals("Not implemented exception expecte",expected.errorCode,ErrorCodes.NOT_IMPLEMENTED);
256 }
257 }
258
259
260
261
262 }